﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SchoolCardSystem
{
    public partial class index : System.Web.UI.Page
    {
        //定义数据库信息
        MySqlConnection connection = new MySqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString());
        protected void Page_Load(object sender, EventArgs e)
        { 
            //打开数据库
            connection.Open();
            //获取了上个页面返回的卡号
            String userId = Session["name"].ToString();
            userName.Text = userId;
            string sqlstr = @"select cardPrice from card where cardId=@userId";
            //Command 查询语句
            MySqlCommand cmd = new MySqlCommand(sqlstr, connection);
            //设置@userId的类型
            cmd.Parameters.Add(new MySqlParameter("@userId", MySqlDbType.VarChar, 11));
            cmd.Parameters["@userId"].Value = userId;
            //在线模式
            MySqlDataReader dr = cmd.ExecuteReader();
            //查询失败
            if (!dr.Read())
            {

            }
            //查询成功
            else
            {
                priceLb.Text = dr["cardPrice"].ToString();
            }
            connection.Close();
        }

        protected void logout_Click(object sender, EventArgs e)
        {
            //注销登录状态
            Session.Clear();
            Response.Redirect("login.aspx");
        }
    }
}